package com.cppe;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.renderscript.ScriptGroup;
import android.telephony.mbms.MbmsErrors;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;

import com.cppe.entity.Camera;
import com.cppe.entity.Video;
import com.cppe.http.HttpCallBack;
import com.cppe.http.RxHttp;
import com.cppe.ui.common.TreeActivity;
import com.cppe.ui.video.ListMultiVideoActivity;
import com.cppe.ui.video.VideoActivity;
import com.google.gson.Gson;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import io.reactivex.disposables.Disposable;

public class MainActivity extends AppCompatActivity {


    Button mButtonV;

    Button mButton;
    Button mButtonT;



    ProgressDialog progressDialog;
    Disposable mDisposable;


    @Override
    protected void onCreate(Bundle savedInstanceState) {


        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mButton = findViewById(R.id.main_btn_login);
        progressDialog = new ProgressDialog(MainActivity.this);
        progressDialog.setTitle("加载中...");
        mButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startVideo();
            }
        });
        mButtonV = findViewById(R.id.main_btn_videos);
        mButtonV.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startVideo2();
            }
        });

        mButtonT = findViewById(R.id.main_btn_tree);
        mButtonT.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startTreeView();
            }
        });


    }

    private void startTreeView() {

        Intent intent = new Intent(MainActivity.this, TreeActivity.class);
        startActivity(intent);
    }

    void startVideo2() {
        Intent intent = new Intent(MainActivity.this, ListMultiVideoActivity.class);




        startActivity(intent);

    }

    void startVideo() {


        Intent intent = new Intent(MainActivity.this, VideoActivity.class);
        Camera camera = new Camera();
        camera.setUrl("http://218.89.187.229:7086/live/cameraid/1000761%240/substream/3.m3u8");
        camera.setName("成都作业区_简阳市简三路252号_0045");
        Bundle bundle = new Bundle();
        bundle.putSerializable("camera", camera);
        intent.putExtras(bundle);
        startActivity(intent);
    }

    public void getVideo() {
        HttpCallBack httpCallBack = new HttpCallBack() {
            @Override
            public void start(Disposable disposable) {
                mDisposable = disposable;
                progressDialog.show();
            }

            @Override
            public void success(String data) {
                Gson gson = new Gson();
                Video video = gson.fromJson(data, Video.class);
                mButton.setText(video.data.name);
            }

            @Override
            public void error(String error) {
                Log.e("ddddd", error);
            }

            @Override
            public void complete() {
                progressDialog.hide();
            }
        };
        Map<String, Object> map = new HashMap<>();
        map.put("name", "");
        RxHttp.post("http://192.168.110.157:8081/departments/tree", map, httpCallBack);
    }

    @Override
    protected void onDestroy() {
        if (!mDisposable.isDisposed()) {
            mDisposable.dispose();
        }
        super.onDestroy();

    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    public void onBackPressed() {

        super.onBackPressed();
    }
}